
#include <bits/types/struct_rusage.h>
#include <stdio.h>
#include <sys/resource.h>

void pr_cpu_time(void) {

  double user, sys;

  struct rusage myusage, childusage;

  if (getrusage(RUSAGE_SELF, &myusage) < 0) {

    printf("getrusage error....\n");
  }
  if (getrusage(RUSAGE_CHILDREN, &childusage) < 0) {

    printf("getrusage error....\n");
  }

  user = (double)myusage.ru_utime.tv_sec +(double) myusage.ru_utime.tv_usec / 1000000.0;
  user+=(double)childusage.ru_utime.tv_sec + (double)childusage.ru_utime.tv_usec / 1000000.0;

  sys = (double)myusage.ru_stime.tv_sec + (double)myusage.ru_stime.tv_usec / 1000000.0;
  sys += (double)childusage.ru_stime.tv_sec + (double)childusage.ru_stime.tv_usec / 1000000.0;

  printf("\nuser time = %g, sys time = %g\n", user, sys);
  
}
